package model.userModel;

import empty.users.User;

import java.sql.SQLException;
import java.util.List;

public class UserModel {

    public int insert(User user) throws SQLException{
        String sql = "INSERT INTO users (name, gender, age, phone, address, pwd, manger, department_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
        return Tool.DML(sql, user.getName(), user.getGender(), user.getAge(), user.getPhone(), user.getAddress(), user.getPwd(), user.getManger(), user.getDepartment_id());
    }

    public int delete(User uesr) throws SQLException{
        String sql = "DELETE FROM users WHERE id = ?";
        return Tool.DML(sql, uesr.getId());
    }

    public int update(User user) throws SQLException{
        String sql = "UPDATE users SET name = ?, gender = ?, age = ?, phone = ?, address = ?, pwd = ?, manger = ?, department_id = ? WHERE id = ?";
        return Tool.DML(sql, user.getName(), user.getGender(), user.getAge(), user.getPhone(), user.getAddress(), user.getPwd(), user.getManger(), user.getDepartment_id(), user.getId());
    }

    public List<Object []> findAll(User uesr) throws SQLException{
        String sql = "SELECT * FROM users";
        return Tool.DQL(sql);
    }

    public List<Object []> findByName(User user) throws SQLException{
        String sql = "SELECT * FROM users WHERE name = ?";
        return Tool.DQL(sql, user.getName());
    }

}
